package com.samoiloff.util.data {
	import Array;
	import Boolean;
	import Object;
	import int;

	/**
	 * @author Damirr
	 */
	public class ArrItem {
		
		protected var _arr:Array;

		public function ArrItem() {
			clear();
		}
		
		public function clear():void {
			_arr = [];
		}

		public function destroy():void {
			_arr = null;
		}

		public function get length():int {
			return _arr.length;
		}

		public function set source(arr:Array):void {
			_arr = arr;
		}

		public function get source():Array {
			return _arr;
		}

		public function setItemAt(i:int, item:Object):void {
			_arr[i] = item;
		}

		public function addItem(item:Object):void {
			_arr.push(item);
		}
		
		public function addItemAt(item:Object, i:int):void {
			_arr.splice(i, 0, item);
		}
		
		public function removeItemAt(index:int):Object {
			return _arr.splice(index, 1)[0];
		}

		public function getIndexOf(item:Object):int {
			return _arr.indexOf(item);
		}

		public function contains(item:Object):Boolean {
			return getIndexOf(item) != -1;
		}

		public function removeItem(item:Object):Object {
			var index:int = getIndexOf(item);
			if (index >= 0) { 
				return _arr.splice(index, 1)[0];
			}
			return null;
		}

		public function toArray(): Array {
			return _arr;
		}
	}
}
